package com.itfs.enums;

import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.HashMap;
import java.util.Map;

@Getter
@AllArgsConstructor(access = AccessLevel.PRIVATE)
public enum ColorEnum {

    RED("red","红色"),
    GREEN("green","绿色"),
    BLANK("blank","白色"),
    YELLOW("yellow","黄色");

    //成员变量
    private String name;
    private String value;

    //将数据缓存到map中
    private static final Map<String,String>  map = new HashMap<String,String>();
    static{
        for (ColorEnum color : ColorEnum.values()) {
            map.put(color.getName(),color.getValue());
        }
    }

    //根据name查询value值
    public static String getValueByName(String name){
        return map.get(name);
    }

    /**
     * 重写 String方法
     * @return
     */
    @Override
    public String toString(){
        return this.name + "_" + this.value;
    }

}
